package com.medical.doctor.controller;

import com.medical.common.core.domain.Result;
import com.medical.common.core.web.controller.BaseController;
import com.medical.common.core.web.page.TableDataInfo;
import com.medical.common.log.annotation.Log;
import com.medical.common.log.enums.BusinessType;
import com.medical.common.security.annotation.RequiresPermissions;
import com.medical.doctor.domain.Drug;
import com.medical.doctor.domain.PreAndDiagnostic;
import com.medical.doctor.domain.ReceivePatients;
import com.medical.doctor.service.IReceivePatientsService;
import com.medical.doctor.vo.ReceiveVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 接诊Controller
 *
 * @author medical
 * @date 2024-07-21
 */
@RestController
@RequestMapping("/patients")
public class ReceivePatientsController extends BaseController
{
    @Autowired
    private IReceivePatientsService receivePatientsService;

    /**
     * 查询接诊列表
     */
    @RequiresPermissions("doctor:patients:list")
    @GetMapping("/list")
    public Result<TableDataInfo> list(ReceivePatients receivePatients)
    {
        startPage();
        List<ReceiveVo> list = receivePatientsService.selectReceivePatientsList(receivePatients);
        return getDataTable(list);
    }
//    /**
//     * 获取医生userId信息
//     */
//    @GetMapping(value = "/getUserId/{id}")
//    public Result getUserId(@PathVariable("id") Long id)
//    {
//        Long data = receivePatientsService.selectPatientsById(id);
//        return Result.success(data);
//    }

    /**
     * 药品列表
     * @param drugName
     * @return
     */
    @GetMapping("/drugList")
    public Result<List<Drug>>drugList(@RequestParam(value = "drugName") String drugName){
        List<Drug> list =receivePatientsService.selectDrugList(drugName);
        return Result.success(list);
    }
    /**
     * 生成处方单
     */
    @PostMapping("/prescription")
    public Result prescriptionAdd(@RequestBody PreAndDiagnostic preAndDiagnostic){
        return Result.success(receivePatientsService.perscriptionAdd(preAndDiagnostic));
    }

    /**
     * 获取医生userId信息
     */
    @GetMapping(value = "/getUserId/{id}")
    public Result getUserId(@PathVariable("id") Long id)
    {
        Long data = receivePatientsService.selectPatientsById(id);
        return Result.success(data);
    }

    /**
     * 修改问诊状态
     */
    @GetMapping("/update/{status}")
    public Result update(@PathVariable Integer status)
    {
        return toAjax(receivePatientsService.updateDoctorStatus(status));
    }

    /**
     * 导出接诊列表
     */
//    @RequiresPermissions("doctor:patients:export")
//    @Log(title = "接诊", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, ReceivePatients receivePatients)
//    {
//        List<ReceiveVo> list = receivePatientsService.selectReceivePatientsList(receivePatients);
//        ExcelUtil<ReceiveVo> util = new ExcelUtil<ReceiveVo>(ReceiveVo.class);
//        util.exportExcel(response, list, "接诊数据");
//    }

    /**
     * 获取接诊详细信息
     */
    @RequiresPermissions("doctor:patients:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(receivePatientsService.selectReceivePatientsById(id));
    }

    /**
     * 新增接诊
     */
    @RequiresPermissions("doctor:patients:add")
    @Log(title = "接诊", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody ReceivePatients receivePatients)
    {
        return toAjax(receivePatientsService.insertReceivePatients(receivePatients));
    }

    /*
     * 修改接诊
     */
    @RequiresPermissions("doctor:patients:edit")
    @Log(title = "接诊", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody ReceivePatients receivePatients)
    {
        return toAjax(receivePatientsService.updateReceivePatients(receivePatients));
    }

    /**
     * 删除接诊
     */
    @RequiresPermissions("doctor:patients:remove")
    @Log(title = "接诊", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(receivePatientsService.deleteReceivePatientsByIds(ids));
    }
}
